package demo2;

//连续子数组最大和

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long[] a = new long[n];
        long[] dp = new long[n];
        for(int i = 0; i<n; i++) {
            a[i] = in.nextLong();
        }
        
        dp[0] = a[0];
        long ret = dp[0];
        for(int i = 1; i<n; i++) {
            dp[i] = Math.max(a[i], dp[i-1]+a[i]);
            ret = Math.max(ret,dp[i]);
        }

        System.out.println(ret);
    }
}

//dp[i]: 以第i个元素结尾的最大子数组